const dbService = require('../../../service/dbService');
const { STATUS_CODE } = require('../../../constants');
const validateMomentIsExist = async (ctx, next) => {
  const { moment_id } = ctx.request.body;
  const result = await dbService.query({ id: moment_id }, 'moment');
  if (result && result.length) {
    await next();
  } else {
    const error = {
      code: STATUS_CODE.FORBIDDEN,
      message: 'error, comment not exist of moment!',
    };
    ctx.app.emit('error', new Error(JSON.stringify(error)), ctx);
  }
};
module.exports = validateMomentIsExist;
